package com.springboot.service.impl;


import com.springboot.dao.MemberDao;
import com.springboot.entity.Member;
import com.springboot.result.Result;
import com.springboot.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MemberServiceImpl implements IMemberService {
    @Autowired
    private MemberDao memberDao;

    public List<Member> findAll() {
        return memberDao.findAll();
    }

    public Result<?> add(Member member) {
        memberDao.add(member);
        return Result.success();
    }

    public Result<Integer> updateById(Member member) {
        int count = memberDao.updateById(member);
        if (count != 0) {
            return Result.success();
        } else {
            return Result.fail();
        }
    }

    public Result<Member> findById(Integer id) {
        Member member = memberDao.findById(id);
        if (member == null) {
            return Result.fail();
        } else {
            return Result.success(member);
        }

    }
}
